package com.zx.callback.common.handler;

import com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter;
import org.springframework.http.HttpOutputMessage;
import org.springframework.http.converter.HttpMessageNotWritableException;

import java.io.IOException;
import java.io.OutputStream;

/**
 * Created by wyh on 2017/2/8.
 */
public class FastJsonHttpMessageConverter2 extends FastJsonHttpMessageConverter {

    @Override
    protected void writeInternal(Object obj, HttpOutputMessage outputMessage) throws IOException, HttpMessageNotWritableException {
        if (obj instanceof String) {
            if (obj != null) {
                OutputStream out = outputMessage.getBody();
                String str = (String)obj;
                byte[] bytes = str.getBytes(getCharset());
                out.write(bytes);
            }
        } else {
            super.writeInternal(obj, outputMessage);
        }
    }
}
